﻿Imports MySql.Data.MySqlClient
Imports System.IO
Public Class DB
    Public Path_SQL As String
    Public response As Object
    Private Sub DB_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub

    Private Sub btn_export_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_export.Click
        FolderBrowserDialog1.Description = "Pick Folder to store Excecl files"
        FolderBrowserDialog1.ShowNewFolderButton = True
        FolderBrowserDialog1.SelectedPath = "C:\"



        If FolderBrowserDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then


            Path_SQL = FolderBrowserDialog1.SelectedPath
            Dim myProcess As New Process()
            myProcess.StartInfo.FileName = "cmd.exe"
            myProcess.StartInfo.UseShellExecute = False
            'myProcess.StartInfo.WorkingDirectory = "C:\Program Files\MySQL\MySQL Server 5.5\bin"
            myProcess.StartInfo.RedirectStandardInput = True
            myProcess.StartInfo.RedirectStandardOutput = True
            myProcess.Start()
            Dim myStreamWriter As StreamWriter = myProcess.StandardInput
            Dim mystreamreader As StreamReader = myProcess.StandardOutput
            myStreamWriter.WriteLine("mysqldump -h 192.168.1.13 -P 3308 -u root -ppisona testremote > " + Path_SQL + "\backup" + Date.Now.Day.ToString + "-" + Date.Now.Month.ToString + "-" + Date.Now.Year.ToString + ".sql")
            myStreamWriter.Close()
            myProcess.WaitForExit()
            myProcess.Close()
            response = MsgBox("Export complete", MsgBoxStyle.Information, "Warning Message")
        End If
        '----------------------------------------


    End Sub

    Private Sub btn_import_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_import.Click
        Dim dialogOpenFiles As OpenFileDialog = New OpenFileDialog()
        dialogOpenFiles.Title = "Open File Dialog"
        dialogOpenFiles.InitialDirectory = "c:\"
        dialogOpenFiles.Filter = "SQL (*.sql)|*.sql"
        dialogOpenFiles.FilterIndex = 1
        dialogOpenFiles.RestoreDirectory = True
        If dialogOpenFiles.ShowDialog() = DialogResult.OK Then
            Path_SQL = dialogOpenFiles.FileName
            response = MsgBox("Are You Sure Export Database ", MsgBoxStyle.Information + MsgBoxStyle.YesNo, "Warning Message")
            If response = 6 Then
                Dim myProcess As New Process()
                myProcess.StartInfo.FileName = "cmd.exe"
                myProcess.StartInfo.UseShellExecute = False
                'myProcess.StartInfo.WorkingDirectory = "C:\Program Files\MySQL\MySQL Server 5.5\bin"
                myProcess.StartInfo.RedirectStandardInput = True
                myProcess.StartInfo.RedirectStandardOutput = True
                myProcess.Start()
                Dim myStreamWriter As StreamWriter = myProcess.StandardInput
                Dim mystreamreader As StreamReader = myProcess.StandardOutput
                myStreamWriter.WriteLine("mysql -h 192.168.1.13 -P 3308 -u root -ppisona testremote < " + Path_SQL)
                myStreamWriter.Close()
                myProcess.WaitForExit()
                myProcess.Close()
                response = MsgBox("Export complete", MsgBoxStyle.Information, "Warning Message")
            Else
                Exit Sub
            End If
        End If


        '------------------
            End Sub
End Class